﻿using HotChocolate.Resolvers;

namespace SimpleGraphQLDemo.WebApi.GraphFieldMiddlewares
{
    public class FieldMiddleware
    {
        private readonly FieldDelegate _next;

        public FieldMiddleware(FieldDelegate next)
        {
            _next = next;
        }

        public async Task InvokeAsync(IMiddlewareContext context)
        {
            var field = context.Selection.Field;
            var syntaxNode = context.Selection.SyntaxNode;
            if (field.Member == null)
            {
                Console.WriteLine($"{field.Name}-ResolverMember-{field.ResolverMember?.MemberType}");
            }
            else
            {
                Console.WriteLine($"{field.Name}-Member-{field.Member?.MemberType}");
            }
            await _next(context);
        }
    }
}
